package com.fastloan.core.apiauth.base.endecrypt.impl;

import com.fastloan.core.apiauth.base.endecrypt.EnDecrypt;
import com.fastloan.core.apiauth.base.util.AesUtil;

import java.io.UnsupportedEncodingException;

/**
 * AES/ECB
 *
 * @author yanwe
 * createTime 2018-01-2018/1/3 17:43
 */
public class AesECB implements EnDecrypt{

    private String aesKey;

    public AesECB(String aesKey) {
        this.aesKey = aesKey;
    }

    public String getAesKey() {
        return aesKey;
    }

    public void setAesKey(String aesKey) {
        this.aesKey = aesKey;
    }

    @Override
    public String encrypt(String data) {
        return AesUtil.encryptByECB(data,aesKey);
    }

    @Override
    public String decrypt(String data) {
        try {
            return new String(AesUtil.decryptByECB(data,aesKey),"UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }
}
